/**
 * 
 */
package com.avocado.base.entity;


import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;




@Entity
@Table(name="AVO_USER_ROLE")
@Data
public class UserRole implements Serializable{

 /**
	 * 
	 */
	private static final long serialVersionUID = 1821439357696364763L;
	
 @EmbeddedId
 @AttributeOverrides( {
 @AttributeOverride(name="userId", column=@Column(name="USER_ID", nullable=false) ), 
 @AttributeOverride(name="roleId", column=@Column(name="ROLE_ID", nullable=false) ) } )
 private UserRoleId id;
	
 @ManyToOne(fetch=FetchType.EAGER)
 @JoinColumn(name="USER_ID", nullable=false, insertable=false, updatable=false)
 private User user; //用户
 
 @ManyToOne(fetch=FetchType.EAGER)
 @JoinColumn(name="ROLE_ID", nullable=false, insertable=false, updatable=false)
 private Role role;//角色
 
 @Temporal(TemporalType.TIMESTAMP)
 @Column(name="EXPIRED_DATE")
 private Date expiredDate;//过期日期
 
 @Temporal(TemporalType.TIMESTAMP)@Column(nullable=false,name="CREATE_TIME")
 private Date createTime=new Date();


 @Override
 public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  UserRole userRole = (UserRole) o;
  return Objects.equals(id, userRole.id);
 }

 @Override
 public int hashCode() {
  return Objects.hash(id);
 }
}
